package com.spring.security.common.enums;

import lombok.Data;

/**
 * 设备状态
 */

public enum DeviceState {
    NORMAL(0, "正常"),
    ABNORMAL(1, "异常"),
    IN_FAULT(2, "故障中"),
    IN_REPAIR(3, "维修中"),
    SCRAP(4, "报废");

    DeviceState(Integer code, String description){
        this.code = code;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    private Integer code;

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    private String description;

    /**
     * 根据状态码获取设备描述
     * @param code
     * @return
     */
    public static String getDescriptionByCode(Integer code){
        for(DeviceState ds : values() ){
            if(ds.getCode().equals(code)){
                return ds.getDescription();
            }
        }
        return null;
    }
}
